<script lang="ts" setup>
import type { AiTrainingDatasetMetaApi } from '#/api/ai/dataset/trainingDatasetMeta';

import { ref } from 'vue';

import { useVbenDrawer } from '@vben/common-ui';

import { getTrainingDatasetMeta } from '#/api/ai/dataset/trainingDatasetMeta';
import { useDescription } from '#/components/description';

import { useDetailSchema } from '../data';

const formData = ref<AiTrainingDatasetMetaApi.TrainingDatasetMeta>();

const [Descriptions] = useDescription({
  bordered: true,
  size: 'middle',
  column: 2,
  labelWidth: 120,

  schema: useDetailSchema(),
});

const [Drawer, drawerApi] = useVbenDrawer({
  async onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      formData.value = undefined;
      return;
    }
    let data =
      drawerApi.getData<AiTrainingDatasetMetaApi.TrainingDatasetMeta>();
    if (!data || !data.id) {
      return;
    }
    drawerApi.lock();
    try {
      data = await getTrainingDatasetMeta(data.id);
      formData.value = data;
    } finally {
      drawerApi.unlock();
    }
  },
});
</script>

<template>
  <Drawer
    title="查看 数据集"
    class="w-[80%]"
    :show-cancel-button="false"
    :show-confirm-button="false"
  >
    <Descriptions :data="formData" class="mx-4" />
  </Drawer>
</template>
